package com.payment.controller.alast;

import com.payment.config.dto.ResultDataDto;
import com.payment.entity.alast.filterpayment.request.RequestFilterPayment;
import com.payment.entity.alast.filterpayment.response.ResponseFilterPayment;
import com.payment.entity.alast.paypalpay.request.RequestPayPalWebPay;
import com.payment.entity.alast.paypalpay.response.ResponsePayPalWebPay;
import com.payment.entity.alast.resultconfirm.request.RequestResultConfirm;
import com.payment.entity.alast.resultconfirm.response.ResponseResultConfirm;
import com.payment.entity.alast.resultquery.request.RequestResultQuery;
import com.payment.entity.alast.resultquery.response.ResponseResultQuery;
import com.payment.entity.alast.showwechatpay.request.RequestShowWeChatPay;
import com.payment.entity.alast.showwechatpay.response.ResponseShowWeChatPay;
import com.payment.entity.alast.stripe.autorenewal.setupintent.request.RequestStripeAutoPay;
import com.payment.entity.alast.stripe.autorenewal.setupintent.response.SetupIntentData;
import com.payment.entity.alast.stripe.autorenewal.subcription.cancel.request.RequestStripeSubCancel;
import com.payment.entity.alast.stripe.autorenewal.subcription.cancel.response.SubscriptionCancelData;
import com.payment.entity.alast.stripe.autorenewal.subcription.directly.request.RequestStripeSubDirectly;
import com.payment.entity.alast.stripe.autorenewal.subcription.directly.response.SubscriptionDirectlyData;
import com.payment.entity.alast.stripe.onetime.request.RequestStripePay;
import com.payment.entity.alast.stripe.onetime.response.CreateStripePaymentData;
import com.payment.entity.alast.wxwebpay.request.RequestWeiXinWebPay;
import com.payment.entity.alast.wxwebpay.response.ResponseWeiXinWebPay;
import com.payment.service.alast.PaymentAndResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 主要用在与前端界面的接口提供
 * <p>
 * 对内技术产品技术使用
 *
 * @author lm
 * @date 2020/7/30 17:08
 */
@RestController
@Api(description = "请求支付和确认结果的控制类")
@CrossOrigin
public class PaymentAndResultController {
    @Autowired
    PaymentAndResultService payAndResultService;

    @CrossOrigin
    @PostMapping(value = "filterPayment", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "过滤支付步骤", response = ResponseFilterPayment.class)
    public ResultDataDto filterPayment(@ApiParam @RequestBody RequestFilterPayment request) {
        return payAndResultService.filterPayment(request);
    }

    @CrossOrigin
    @PostMapping(value = "resultQuery", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "支付结果查询", response = ResponseResultQuery.class)
    public ResultDataDto resultQuery(@ApiParam @RequestBody RequestResultQuery request) {
        return payAndResultService.resultQuery(request);
    }

    @CrossOrigin
    @PostMapping(value = "resultConfirm", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "支付结果确认", response = ResponseResultConfirm.class)
    public ResultDataDto resultConfirm(@ApiParam @RequestBody RequestResultConfirm request) {
        return payAndResultService.resultConfirm(request);
    }

    @CrossOrigin
    @PostMapping(value = "showWeChatPay", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取展示微信支付的渠道集合", response = ResponseShowWeChatPay.class)
    public ResultDataDto showWeChatPay(@ApiParam @RequestBody RequestShowWeChatPay request) {
        return payAndResultService.showWeChatPay(request);
    }

    @CrossOrigin
    @PostMapping(value = "wxWebPay", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取微信网页（H5）支付权限", response = ResponseWeiXinWebPay.class)
    public ResultDataDto wxWebPay(@ApiParam @RequestBody RequestWeiXinWebPay request, HttpServletRequest re) {
        return payAndResultService.wxWebPay(request, re);
    }

    @CrossOrigin
    @PostMapping(value = "payPalPay", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取payPal网页（H5）支付权限", response = ResponsePayPalWebPay.class)
    public ResultDataDto payPalPay(@ApiParam @RequestBody RequestPayPalWebPay request) {
        return payAndResultService.payPalPay(request);
    }

    @CrossOrigin
    @PostMapping(value = "stripePay", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取stripe收银台一次性支付权限", response = CreateStripePaymentData.class)
    public ResultDataDto stripePay(@ApiParam @RequestBody RequestStripePay request) {
        return payAndResultService.stripePay(request);
    }

    @CrossOrigin
    @PostMapping(value = "stripeAutoPay", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取stripe收银台自动续费支付权限", response = SetupIntentData.class)
    public ResultDataDto stripeAutoPay(@ApiParam @RequestBody RequestStripeAutoPay request) {
        return payAndResultService.stripeAutoPay(request);
    }

    @CrossOrigin
    @PostMapping(value = "stripeSubDirectly", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "获取stripe收银台自动续费直接订阅", response = SubscriptionDirectlyData.class)
    public ResultDataDto stripeSubDirectly(@ApiParam @RequestBody RequestStripeSubDirectly request) {
        return payAndResultService.stripeSubDirectly(request);
    }

    @CrossOrigin
    @PostMapping(value = "stripeSubCancel", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "(此接口是纯后端接口)获取stripe收银台自动续费取消订阅", response = SubscriptionCancelData.class)
    public ResultDataDto stripeSubCancel(@ApiParam @RequestBody RequestStripeSubCancel request) {
        return payAndResultService.stripeSubCancel(request);
    }
}
